package com.vben.ai.service;

import com.vben.ai.constant.ModelConstant;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import static com.vben.ai.constant.ModelConstant.DEFAULT_PROMPT;

/**
 * AI对话服务类
 *
 * @author sunnfun
 */
@Service
public class ChatService {

    @Resource
    @Qualifier("deepseekChatClient")
    private ChatClient deepseekChatClient;

    @Resource
    @Qualifier("qwenMaxChatClient")
    private ChatClient qwenMaxChatClient;

    public String simple(String model, String message) {
        if (ModelConstant.Qwen_Max.equals(model)) {
            return qwenMaxChatClient
                    .prompt(DEFAULT_PROMPT)
                    .user(message)
                    .call()
                    .content();
        } else if (ModelConstant.DEEP_SEEK_R1.equals(model)) {
            return deepseekChatClient
                    .prompt(DEFAULT_PROMPT)
                    .user(message)
                    .call()
                    .content();
        }
        return "未找到对应模型";
    }

    public Flux<String> stream(String model, String message) {
        if (ModelConstant.Qwen_Max.equals(model)) {
            return qwenMaxChatClient
                    .prompt(DEFAULT_PROMPT)
                    .user(message)
                    .stream()
                    .content();
        } else if (ModelConstant.DEEP_SEEK_R1.equals(model)) {
            return deepseekChatClient
                    .prompt(DEFAULT_PROMPT)
                    .user(message)
                    .stream()
                    .content();
        }
        return Flux.just("未找到对应模型");
    }
}
